//
//  UIBarButtonItem+extension.m
//  netEasy
//
//  Created by mac on 15/10/31.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "UIBarButtonItem+extension.h"

@implementation UIBarButtonItem (extension)

+(instancetype)barButtonItemWith:(UIImage *) nomalImage highlighted:(UIImage *) hightlightedImage action:(SEL) action target:(id) target
{
    
    //设置按钮的图片和操作
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setImage:nomalImage forState:UIControlStateNormal];
    
    [btn setImage:hightlightedImage forState:UIControlStateHighlighted];
    
    [btn sizeToFit];
    
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //将按钮设置到BARBUTTONITEM上面去
    UIBarButtonItem * barItem =[[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return barItem;
}

@end
